<?php
namespace app\admin\controller;
use app\admin\model\AdminGroup as AdminGroupModel;
use app\admin\controller\Base;

class AdminGroup extends Base
{
    public function index()
    {
        $adminGroupRes=AdminGroupModel::paginate(6);
        $this->assign('adminGroupRes',$adminGroupRes);
        $this->assign('title','管理员组列表');
        return $this->fetch();
    }

    public function add()
    {
        if(request()->isPost()){
            $data=input('post.');
            if($data['rules']){
                $data['rules']=implode(',', $data['rules']);
            }
            $add=db('admin_group')->insert($data);
            if($add){
                $this->success('添加管理员组成功！',url('index'));
            }else{
                $this->error('添加管理员组失败！');
            }
            return;
        }
        $adminRule=new \app\admin\model\AdminRule();
        $adminRuleRes=$adminRule->adminRuleTree();
        $this->assign('adminRuleRes',$adminRuleRes);
        return $this->fetch();
    }

    public function edit()
    {
        if(request()->isPost()){
            $data=input('post.');
            if($data['rules']){
                $data['rules']=implode(',', $data['rules']);
            }
            $_data=array();
            foreach ($data as $k => $v) {
                $_data[]=$k;
            }
            if(!in_array('status', $_data)){
                $data['status']=0;
            }
            $save=db('admin_group')->update($data);
            if($save!==false){
                $this->success('修改管理员组成功！',url('index'));
            }else{
                $this->error('修改管理员组失败！');
            }
            return;
        }
        $adminGroups=db('admin_group')->find(input('id'));
        $this->assign('admingroups',$adminGroups);
        $adminRule=new \app\admin\model\AdminRule();
        $adminRuleRes=$adminRule->adminRuleTree();
        $this->assign('adminRuleRes',$adminRuleRes);
        return $this->fetch();
    }

    public function del()
    {
        $del=db('admin_group')->delete(input('id'));
        if($del){
            $this->success('删除管理员组成功！',url('index'));
        }else{
            $this->error('删除管理员组失败！');
        }
    }


    
    




   

	












}
